# -*- coding: utf-8 -*-
# @Time : 2024/3/28 10:16
# @Author : ZH
# @File : 1997.py
# @Software: PyCharm
class Solution(object):
    def firstDayBeenInAllRooms(self, nextVisit):
        """
        :type nextVisit: List[int]
        :rtype: int
        """
        mod = 10 ** 9 + 7
        dp = [0] * (len(nextVisit))

        # 初始化原地待一天+访问下一个房间一天
        dp[0] = 2
        for i in range(1, len(nextVisit)):
            to = nextVisit[i]
            dp[i] = 2 + dp[i - 1]
            if to != 0:
                dp[i] = (dp[i] - dp[to - 1]) % mod
            dp[i] = (dp[i] + dp[i - 1]) % mod
        return dp[len(nextVisit) - 2]  # 题目保证n >= 2

if __name__ == '__main__':
    so = Solution()
    l = so.firstDayBeenInAllRooms([0,0,2])
    print(l)
    # for day in range(100):
    #     print((day + 1) % 2)
